package com.kennedy.springboot.service;

import com.github.pagehelper.PageHelper;
import com.kennedy.springboot.beans.Shop;
import com.kennedy.springboot.mapper.ShopMapper;
import com.kennedy.springboot.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by tao.zeng on 2017/7/28.
 */
@Service
public class ShopService {
    @Autowired
    private ShopMapper shopMapper;

    public void insert(Shop shop) {
        shop.setCreateTime(DateUtil.getCurrentTime());
        shopMapper.insert(shop);
    }

    public Shop selectOne(long id) {
        return shopMapper.selectByPrimaryKey(id);
    }

    public List<Shop> selectAll() {
        return shopMapper.selectAll();
    }

    public List<Shop> getListByPage(Shop shop) {
        if (shop.getOffset() != null && shop.getLimit() != null) {
            PageHelper.offsetPage(shop.getOffset(), shop.getLimit());
        }
        return shopMapper.selectAll();
    }
}
